package com.hnqcgc.service.impl;

import com.hnqcgc.dao.IAdminDao;
import com.hnqcgc.dao.impl.AdminDaolmpl;
import com.hnqcgc.db.MyTransaction;
import com.hnqcgc.service.IAdminService;
import com.hnqcgc.vo.TAdmin;

import java.sql.SQLDataException;
import java.sql.SQLException;
import java.util.List;

public class AdminServicelmpl implements IAdminService{
    MyTransaction myTransaction=new MyTransaction(true);
    IAdminDao dao=new AdminDaolmpl(myTransaction);


    @Override
    public TAdmin login(String adminName, String adminPassword) {
        MyTransaction myTransaction=new MyTransaction(true);
        IAdminDao dao=new AdminDaolmpl(myTransaction);
        try {
            return dao.login(adminName,adminPassword);
        }catch (SQLException throwables){
            throwables.printStackTrace();
            System.err.println("查询失败");
        }
        return null;
    }

    @Override
    public List<TAdmin> queryAll() {
        try {
            return dao.queryAll();
        }catch (SQLException throwables){
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public List<TAdmin> queryByNameLike(String adminName) {
        try {
            return dao.queryByNameLike(adminName);
        }catch (SQLException throwables){
            throwables.printStackTrace();
            return null;
        }
    }

    @Override
    public int adminInsert(TAdmin admin) {
        return dao.insert(admin);
    }

    @Override
    public int adminUpdate(TAdmin admin) {
        return dao.update(admin);
    }

    @Override
    public int adminDelete(long adminId) {
        return dao.delete(adminId);
    }
}


